

package text_modification;
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;

public class ReadFile {
    private String path;
    public  ReadFile(String file_path){
        path = file_path;
    }
    public String[] OpenFile() throws IOException{
        int i;
        int numberOfLines = readline();
        String[] textdata = new String[numberOfLines];
        FileReader fr = new FileReader(path);
        BufferedReader text_reader = new BufferedReader(fr);
        for(i=0;i<numberOfLines;i++){
            textdata[i] = text_reader.readLine();
        }
        text_reader.close();
        return textdata;
    }
    
    /**
     * This function read in all line of the text file
     * @all lines of text file in an array of strins
     * @throws IOException 
     */
    int readline() throws IOException{
        FileReader file_read = new FileReader(path);
        BufferedReader bf = new BufferedReader(file_read);
        String aLine;
        int numberOfLines = 0;
        
        while((aLine = bf.readLine()) != null){
            numberOfLines++;
        }
        return numberOfLines;
    }
}
